package cn.bs.busuo.front.content.controller;

import cn.bs.busuo.common.pojo.authentication.CurrentPrincipal;
import cn.bs.busuo.common.web.JsonResult;
import cn.bs.busuo.front.content.pojo.param.CommentHotelAddNewParam;
import cn.bs.busuo.front.content.pojo.param.CommentSightAddNewParam;
import cn.bs.busuo.front.content.service.UserCommentService;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

/**
 * @author: Feng
 * @since: 2023/12/8
 */
@RestController
@Slf4j
@RequestMapping("/comment")
@Api(tags = "1.评论")
public class UserCommentController {

    @Autowired
    private UserCommentService userCommentService;

    @PostMapping("/hotelComment/{id}")//酒店文章的id
    @PreAuthorize("hasAuthority('/account/user/normal')")
    @ApiOperation("评论酒店文章")
    @ApiOperationSupport(order = 100)
    public JsonResult addNewHotelArticleComment(@AuthenticationPrincipal @ApiIgnore CurrentPrincipal currentPrincipal,
                                         @PathVariable @ApiIgnore("id") Long id, CommentHotelAddNewParam commentHotelAddNewParam) {
        userCommentService.commentHotelArticleDetailById(currentPrincipal,id,commentHotelAddNewParam);
        return JsonResult.ok();
    }

    @PostMapping("/hotelComment/comment/{id}")//酒店文章评论的id
    @PreAuthorize("hasAuthority('/account/user/normal')")
    @ApiOperation("评论酒店文章的评论(多级评论)")
    @ApiOperationSupport(order = 200)
    public JsonResult addNewHotelArticleCommentComment(@AuthenticationPrincipal @ApiIgnore CurrentPrincipal currentPrincipal,
                                         @PathVariable @ApiIgnore("id") Long id, CommentHotelAddNewParam commentHotelAddNewParam) {
        userCommentService.commentHotelArticleDetailCommentById(currentPrincipal,id,commentHotelAddNewParam);
        return JsonResult.ok();
    }

    @PostMapping("/DeleteHotelComment/{id}")//酒店文章评论的id
    @PreAuthorize("hasAuthority('/account/user/normal')")
    @ApiOperation("删除酒店文章的评论")
    @ApiOperationSupport(order = 300)
    public JsonResult deleteHotelArticleComment(@AuthenticationPrincipal @ApiIgnore CurrentPrincipal currentPrincipal,
                                                       @PathVariable @ApiIgnore("id") Long id) {
       userCommentService.deleteHotelArticleCommentById(currentPrincipal,id);
        return JsonResult.ok();
    }


    @PostMapping("/sightComment/{id}")
    @PreAuthorize("hasAuthority('/account/user/normal')")
    @ApiOperation("评论景点文章")
    @ApiOperationSupport(order = 500)
    public JsonResult addNewSightArticleComment(@AuthenticationPrincipal @ApiIgnore CurrentPrincipal currentPrincipal,
                                         @PathVariable @ApiIgnore("id") Long id, CommentSightAddNewParam commentSightAddNewParam) {
        userCommentService.commentSightArticleDetailById(currentPrincipal,id,commentSightAddNewParam);
        return JsonResult.ok();
    }

    @PostMapping("/sightComment/comment/{id}")//景点文章评论的id
    @PreAuthorize("hasAuthority('/account/user/normal')")
    @ApiOperation("评论景点文章的评论(多级评论)")
    @ApiOperationSupport(order = 600)
    public JsonResult addNewSightArticleCommentComment(@AuthenticationPrincipal @ApiIgnore CurrentPrincipal currentPrincipal,
                                                       @PathVariable @ApiIgnore("id") Long id, CommentSightAddNewParam commentSightAddNewParam) {
        userCommentService.addNewSightArticleCommentComment(currentPrincipal,id,commentSightAddNewParam);
        return JsonResult.ok();
    }

    @PostMapping("/DeleteSightComment/{id}")//景点文章评论的id
    @PreAuthorize("hasAuthority('/account/user/normal')")
    @ApiOperation("删除酒店文章的评论")
    @ApiOperationSupport(order = 300)
    public JsonResult deleteSightArticleComment(@AuthenticationPrincipal @ApiIgnore CurrentPrincipal currentPrincipal,
                                                @PathVariable @ApiIgnore("id") Long id) {
        userCommentService.deleteSightArticleCommentById(currentPrincipal,id);
        return JsonResult.ok();
    }
}
